define(['moment', 'module/moduleA/program/B01/B0102/PrintSettingService'], function (moment) {
        return ['$scope', '$filter', '$stateParams', 'config', 'MMWService', 'PrintSetting', '$datePicker', "$mdDialog",'$mddProvider',
                function ($scope, $filter, $stateParams, config, $MMWService, $PrintSetting, $datePicker, $mdDialog,$mddProvider) {

                        $scope._event = {};
                        $scope._fn = {};
                        //  $scope._fn.Execute.isShown="Y";

                        // $scope._fn['Execute'].isShown == 'N';
                        $scope.init = function () {
                                $scope.mode = 'query';
                                $scope.item_no = '';
                                $scope.item_name = '';
                                $scope.wo_no = '';
                                $scope.plot_no = '';
                                $scope.wo_no_s = '';
                                $scope.wo_no_e = '';
                                $scope.B0102_Table = []; // 列印詳情
                                $scope.B0102_Table = [];//區域內的機台列表
                                $scope.printList = []; // 列印詳情
                                // $scope._fn.Execute.isShown = 'N';
                                $scope._fn.B0102_preview.isShown = 'N';
                                $scope.iframeStyle = false;

                        };

                        $scope.back = function () {
                                if ($scope.mode == 'print') {
                                        $scope.mode = 'preview';
                                        document.getElementById('kmi-pdf-panel').src = '';
                                } else {
                                        $scope.$root.hideMenu();
                                        $scope.$root.changeProgram('home', true);
                                }
                        };

                        $scope.barcodeScan = function (event) {
                                if (event.keyCode == 13) {
                                        $scope.search();
                                }
                        };

                        $scope._fn['Execute'] = {
                                click: () => {
                                        $scope.search();

                                }
                        }
                        $scope.search = function () {
                                //if($scope.mode == 'query'){
                                if ($scope.item_no == '' && $scope.wo_no == '' && $scope.wo_no_s == '' && $scope.wo_no_e == '' && $scope.plot_no == '') {
                                        $scope.$root.showAlert($filter('translate')('B0102.showAlert.column3'));
                                        return;
                                }
                                $MMWService.sendToServer({
                                        uri: 'ServicesSTD.Module_WIP.runcard_info_get',
                                        content: {
                                                item_no: $scope.item_no,//產品
                                                wo_no: $scope.wo_no,//工單號碼
                                                plot_no: $scope.plot_no,//生產批
                                                wo_no_s: $scope.wo_no_s,
                                                wo_no_e: $scope.wo_no_e
                                        },
                                        success: function (data) {
                                                $scope.mode = 'list';
                                                $scope.B0102_Radio_Box.feedback_type_1 = false;
                                                $scope.B0102_Table = data.details;
                                        },
                                        error: function (data) {
                                                $scope.$root.showAlert(data.Message);
                                                $scope.mode = 'query';
                                                $scope.B0102_Radio_Box.feedback_type_1 = false;
                                                $scope.B0102_Table = [];
                                        }
                                });
                                //} else {
                                //    $scope.mode = 'query';
                                //}
                        };




                        $scope._event['item_no'] = {
                                click: () => {
                                        $MMWService.showQueryListPNIG({
                                                form_name: 'PageNo_46',
                                                key: 'page_no',
                                                pageRecord: 50,
                                                condition: [
                                                        { name: $filter('translate')('common.queryList.item_c'), column_name: 'ProductNo', query_mode: '2', value: $scope.item_no },
                                                        { name: $filter('translate')('common.queryList.item_n'), column_name: 'ProductName', query_mode: '2', value: '' }
                                                ],
                                                header: [
                                                        { label: $filter('translate')('common.queryList.item_c'), code: 'page_no' },
                                                        { label: $filter('translate')('common.queryList.item_n'), code: 'page_name' }
                                                ],
                                                selectCode: $scope.item_no,
                                                confirm: function (selectItem) {
                                                        $scope.item_no = selectItem.page_no;
                                                        $scope.item_name = selectItem.page_name;
                                                        $scope.item_display = selectItem.page_name + '(' + selectItem.page_no + ')';
                                                }
                                        });
                                }

                        };
                        // 工单号码查询  load_wo_noList

                        // 20200113 modify by WeiTing for M#66480 - 需要判斷 生產批預計開工時間 來呈現 工單狀態，所以改用 showQueryList。
                        $scope._event['wo_no'] = {
                                click: (wo_no) => {
                                        $scope.load_wo_noList('wo_no')
                                }
                        };
                        $scope._event['line'] = {
                                click: () => {
                                        $scope.load_wo_noList()
                                }
                        };
                        // 
                        $scope._event['wo_no_s'] = {
                                click: (wo_no_s) => {
                                        $scope.load_wo_noList('wo_no_s')
                                }
                        };
                        // 
                        $scope._event['wo_no_e'] = {
                                click: (wo_no_e) => {
                                        $scope.load_wo_noList('wo_no_e')
                                }
                        };
                        $scope._event['pdf_panel'] = {
                                isShown:'N'
                        }
                        $scope._event['pdf_footer'] = {
                                isShown:'N'
                        }
        
                        $scope.$watch('mode', (mode) => {
                                if (mode == 'print'){
                                        $scope._event['pdf_panel'].isShown = 'Y'
                                        $scope._event['pdf_footer'].isShown = 'Y'
                                }
                                if(mode == 'preview') {
                                        $scope._event['pdf_panel'].isShown = 'N'
                                        $scope._event['pdf_footer'].isShown = 'N'
                                        $scope._fn['Execute'].isShown = 'N'
                                        $scope._fn['B0102_preview'].isShown = 'Y'
                                }
                                if(mode == 'list') {
                                        $scope._fn['B0102_preview'].isShown = 'N'
                                        $scope._fn['Execute'].isShown = 'Y'
                                }
                        });

                        $scope.load_wo_noList = function (target) {
                                $scope.$root.showQueryList({
                                        key: 'page_no',
                                        pageRecord: 50,
                                        header: [
                                                { label: $filter('translate')('common.queryList.wo_c'), code: 'page_no' },
                                                { label: $filter('translate')('common.queryList.item_c'), code: 'productno' },
                                                { label: $filter('translate')('common.queryList.item_n'), code: 'productname' },
                                                { label: $filter('translate')('common.queryList.item_spec'), code: 'itemspec' },
                                                { label: $filter('translate')('B0102.queryList.wo_no_create_date'), code: 'create_date' },
                                                { label: $filter('translate')('B0102.queryList.plot_no_plan_start_date'), code: 'plan_start_date' },
                                                { label: $filter('translate')('B0102.queryList.wo_no_state'), code: 'wo_no_state' }
                                        ],
                                        query: function (conditions, feedback) {
                                                var query_condition_info = [
                                                        { column_name: 'MOSTATE', query_mode: '0', value: '3', merge_condition_model: 'AND' }
                                                ];
                                                if ($scope.item_no && $scope.item_no != '') {
                                                        query_condition_info.push({ column_name: 'A.productno', query_mode: '2', value: $scope.item_no, merge_condition_model: 'AND' });
                                                }
                                                $MMWService.pageNumberInfoGet({
                                                        form_name: 'PageNo_3',
                                                        query_condition_info: query_condition_info
                                                }, function (itemList) {

                                                        //20220908 add by wangqq for M#0118758：流程卡列印防呆
                                                        if (itemList === undefined || itemList.length == 0) {
                                                                $scope.$root.showAlert($filter('translate')('B0102.queryList.nodata'));
                                                                return;
                                                        }
                                                        //20210608 modify by kaiinagami for M#92928 - 分新舊邏輯跑2種規格
                                                        // 判斷生產批預計開工時間
                                                        if (itemList[0].cnts_dis === undefined) {
                                                                //old logic
                                                                for (var i = 0; i < itemList.length; i++) {
                                                                        if (itemList[i].plan_start_date == '1900-01-01 00:00:00') {
                                                                                // 未派工
                                                                                itemList[i].wo_no_state = $filter('translate')('B0102.queryList.unassigned');
                                                                        } else if (itemList[i].plan_start_date == '') {
                                                                                // 未开批
                                                                                itemList[i].wo_no_state = $filter('translate')('B0102.queryList.unapproved');
                                                                        } else {
                                                                                // 已派工
                                                                                itemList[i].wo_no_state = $filter('translate')('B0102.queryList.assigned');
                                                                        };
                                                                };
                                                        }
                                                        else {
                                                                //20210608 modify by kaiinagami for M#92928 - 新加邏輯
                                                                itemList.forEach(function (item) {
                                                                        if (item.cnts_lot == 0) {
                                                                                item.wo_no_state = $filter('translate')('B0102.queryList.unapproved');
                                                                        }
                                                                        else {
                                                                                if (item.cnts_dis > 0) {
                                                                                        item.wo_no_state = $filter('translate')('B0102.queryList.assigned');
                                                                                }
                                                                                else {
                                                                                        item.wo_no_state = $filter('translate')('B0102.queryList.unassigned');
                                                                                }
                                                                        }
                                                                });
                                                        }
                                                        feedback(itemList);
                                                });
                                        },
                                        selectCode: $scope[target],
                                        confirm: function (selectItem, dialog) {
                                                dialog.hide();
                                                $scope[target] = selectItem.page_no;
                                        }
                                });
                        };

                        var selectNum = 0;
                        $scope.isSelectAll = false;
                        $scope._event['B0102_Table'] = {
                                select: () => {
                                        if ($scope.B0102_Table.length > 0) {
                                                $scope.isSelectAll = !$scope.isSelectAll;
                                                $scope.B0102_Table.forEach(function (item) {
                                                        item.isSelect = $scope.isSelectAll;
                                                });
                                                if ($scope.isSelectAll) {
                                                        selectNum = $scope.B0102_Table.length;
                                                        $scope.mode = 'preview';
                                                } else {
                                                        selectNum = 0;
                                                        $scope.mode = 'list';
                                                }
                                        }
                                }
                        }
                        $scope.selectAll = function () {
                                if ($scope.B0102_Table.length > 0) {
                                        $scope.isSelectAll = !$scope.isSelectAll;
                                        $scope.B0102_Table.forEach(function (item) {
                                                item.isSelect = $scope.isSelectAll;
                                        });
                                        if ($scope.isSelectAll) {
                                                selectNum = $scope.B0102_Table.length;
                                                $scope.mode = 'preview';
                                        } else {
                                                selectNum = 0;
                                                $scope.mode = 'list';
                                        }
                                }
                        };
                        //   _event['B0102_Table'].checkSelect(item, 'B0102_Table.item');
                        //     $scope._event['B0102_Table'] = { checkSelect:(item)=>{
                        //         item.isSelect = !item.isSelect;
                        //         if(item.isSelect){
                        //             selectNum++;
                        //         } else {
                        //             selectNum--;
                        //             $scope.isSelectAll = false;
                        //         }

                        //         if(selectNum<=0){
                        //             selectNum = 0;
                        //             $scope.mode = 'list';
                        //         } else {
                        //             $scope.mode = 'preview';
                        //         }
                        //        }
                        //    };
                        $scope._event['B0102_Table'] = {
                                select: (item) => {
                                        item.isSelect = !item.isSelect;
                                        if (item.isSelect) {
                                                selectNum++;
                                        } else {
                                                selectNum--;
                                                $scope.isSelectAll = false;
                                        }

                                        if (selectNum <= 0) {
                                                selectNum = 0;
                                                $scope.mode = 'list';
                                        } else {
                                                $scope.mode = 'preview';
                                        }
                                }
                        }
                        $scope.itemClick = function (index, item) {
                                item.isSelect = !item.isSelect;
                                if (item.isSelect) {
                                        selectNum++;
                                } else {
                                        selectNum--;
                                        $scope.isSelectAll = false;
                                }

                                if (selectNum <= 0) {
                                        selectNum = 0;
                                        $scope.mode = 'list';
                                } else {
                                        $scope.mode = 'preview';
                                }
                        };
                        // 预览 
                        var pdf_url;
                        $scope._fn['B0102_preview'] = {
                                click: (wo_no_e) => {
                                        $scope.preview();
                                }
                        };

                        $scope.preview = function () {
                                $scope.iframeStyle = true;
                                var plot_detail = [];
                                $scope.B0102_Table.forEach(function (item) {
                                        if (item.isSelect) {
                                                plot_detail.push(item);
                                        }
                                });

                                //20180605 modify by 李栋 for mantis#0047558
                                $MMWService.sendToServer({
                                        uri: 'ServicesSTD.Module_WIP.runcard_pdf_get',
                                        content: {
                                                course: ($scope.B0102_Radio_Box.feedback_type_1 ? '1' : '0'),
                                                plot_detail: plot_detail
                                        },
                                        success: function (data) {

                                                for (var i = 0; i < plot_detail.length; i++) {
                                                        $scope.printList.push({
                                                                printNo: plot_detail[i].plot_no,
                                                                printType: '1' // 1: 流程卡打印 + 生產批開立; 3: 條碼標籤打印(補印); 4: 外包單 - 出貨打印; 5. 叫修作業;
                                                        });
                                                }

                                                pdf_url = data.runcard_pdf_get[0].url_pdf;
                                                if (pdf_url.indexOf('http://') == -1) {
                                                        pdf_url = 'http://' + config.server.ip + ':' + config.server.port + pdf_url;
                                                }
                                                if (config.setting.outsidePDF == 'Y') {
                                                        var fs = window.nodeRequire('fs'), RuncardPath;
                                                        try {
                                                                // 20240321 modify by Alan for#159805 : electron升級後，兼容新舊版本
                                                                const remote = window.nodeRequire('electron').remote || window.nodeRequire('@electron/remote');
                                                                RuncardPath = remote.app.getAppPath();
                                                        } catch (e) {
                                                                RuncardPath = window.nodeRequire('path').dirname(process.execPath) + '\\package.nw';
                                                        }
                                                        RuncardPath += '\\www\\Runcard';
                                                        if (!fs.existsSync(RuncardPath)) {
                                                                fs.mkdirSync(RuncardPath);
                                                        }

                                                        // 20240222 add by Alan for#158151 : 清除Runcard目錄下未開啟的舊檔案
                                                        // 20240408 modify by Alan for#139948 : 改成同步讀取，避免刪除檔案後立即列印造成找不到檔案
                                                        fs.readdirSync(RuncardPath, (err, files) => {
                                                                if (err) {
                                                                        console.log(err);
                                                                }
                                                                //listing all files using forEach
                                                                files.forEach((file) => {
                                                                        // Do whatever you want to do with the file
                                                                        fs.unlink(RuncardPath + '/' + file, (err) => {
                                                                                if (err) {
                                                                                        console.debug(err);
                                                                                }
                                                                        })
                                                                });
                                                        })

                                                        // 20240222 add by Alan for#158151 : 增加時間戳記，避免檔名重複造成檔案開啟時無法寫入
                                                        let pdfPath = `${RuncardPath}/RuncardPreview_${Date.now()}.pdf`;
                                                        $scope.$root.downloadFile(pdf_url, pdfPath, function (dist_path) {
                                                                // 20230807 modify by Alan for#130433 : electron升版後，shell.openItem改成shell.openPath
                                                                const { shell } = window.nodeRequire('electron');
                                                                shell.openItem ? shell.openItem(dist_path) : shell.openPath(dist_path);
                                                        });
                                                } else {
                                                        showPDFViewer(pdf_url);
                                                }
                                        }
                                });
                        };

                        function showPDFViewer(pdf_url) {
                                try {
                                        window.nodeRequire('nw.gui').Window.open(pdf_url, {
                                                title: 'PDF Viewer',
                                                show: false,
                                                icon: 'icon/icon.png',
                                                focus: true
                                        }, function (win) {
                                                win.on('loaded', function () {
                                                        win.show();
                                                        win.print();
                                                });
                                        });
                                } catch (e) {
                                        $scope.mode = 'print';
                                        document.getElementById('kmi-pdf-panel').src = 'JSplugins/pdfjs/web/viewer.html?file=' + pdf_url + '&openfile=false&viewbookmark=false&printfile=false&download=false#zoom=page-width';
                                }
                        }

                        //M#53071: 調整列印的方式，解決列印模糊的問題
                        $scope.print = function () {
                               $scope.iframeStyle = true;
                                if (window.nodeRequire) {
                                        var sumatraPDF = window.nodeRequire('sumatra-pdf');
                                        if (sumatraPDF) {
                                                var fs = window.nodeRequire('fs'), RuncardPath;
                                                try {
                                                        // 20240321 modify by Alan for#159805 : electron升級後，兼容新舊版本
                                                        const remote = window.nodeRequire('electron').remote || window.nodeRequire('@electron/remote');
                                                        RuncardPath = remote.app.getAppPath();
                                                } catch (e) {
                                                        RuncardPath = window.nodeRequire('path').dirname(process.execPath) + '\\package.nw';
                                                }
                                                RuncardPath += '\\www\\Runcard';
                                                if (!fs.existsSync(RuncardPath)) {
                                                        fs.mkdirSync(RuncardPath);
                                                }

                                                // 20240222 add by Alan for#158151 : 清除Runcard目錄下未開啟的舊檔案
                                                // 20240408 modify by Alan for#139948 : 改成同步讀取，避免刪除檔案後立即列印造成找不到檔案
                                                fs.readdirSync(RuncardPath, (err, files) => {
                                                        if (err) {
                                                                console.log(err);
                                                        }
                                                        //listing all files using forEach
                                                        files.forEach((file) => {
                                                                // Do whatever you want to do with the file
                                                                fs.unlink(RuncardPath + '/' + file, (err) => {
                                                                        if (err) {
                                                                                console.debug(err);
                                                                        }
                                                                })
                                                        });
                                                })

                                                // 20240222 add by Alan for#158151 : 增加時間戳記，避免檔名重複造成檔案開啟時無法寫入
                                                let pdfPath = `${RuncardPath}/RuncardPreview_${Date.now()}.pdf`;
                                                $scope.$root.downloadFile(pdf_url, pdfPath, function (dist_path) {
                                                        $scope.$root.showLoading();
                                                        // 20231013 modify by wenwei for M#147137 有的客户家打印需要强制转换，有的不需要，不确定是否是打印机的问题
                                                        window.nodeRequire('sumatra-pdf').printToDefault({
                                                                path: dist_path, settings:'landscape',
                                                                success: function () {
                                                                        printWiplogProcess(); // 列印完成後，需把列印詳情回送給後台做記錄
                                                                        $scope.$root.hideLoading();
                                                                        // 20201104 modify by shiwwl 0151026: 测试正式区，流程卡打印，打印完之后，再回到原界面，只有打印按钮，查询按钮不显示了。
                                                                        selectNum = 0;
                                                                        $scope.$root.showToast($filter('translate')('common.msg.success'));
                                                                },
                                                                error: function (error) {
                                                                        // 20201104 modify by WeiTing for M#77013 - 不清楚為何在實際列印後，有列印成一張紙或輸出成 PDF檔案時，都會執行 error區域，所以目前 error區域也先當列印完成後，把列印詳情回送給後台做記錄。
                                                                        printWiplogProcess(); // 列印完成後，需把列印詳情回送給後台做記錄
                                                                        $scope.$root.hideLoading();
                                                                        selectNum = 0;
                                                                        $scope.$root.showToast($filter('translate')('common.msg.success'));
                                                                        //console.error(error);
                                                                }
                                                        });
                                                });
                                        } else {
                                                window.frames['kmi-pdf-panel'].pdf_print();
                                        }
                                } else {
                                        window.frames['kmi-pdf-panel'].pdf_print();
                                }
                                /*
                                if(config.setting.printSetting){
                                    $PrintSetting.init({
                                        callback:function(settings){
                                            window.frames['kmi-pdf-panel'].pdf_print(settings);
                                        }
                                    });
                                } else {
                                    window.frames['kmi-pdf-panel'].pdf_print();
                                }
                                */
                        };

                        $scope.download = function () {
                                window.frames['kmi-pdf-panel'].pdf_download();
                        };

                        $scope.cancel = function () {
                                if(selectNum >0){
                                    $scope.mode = 'preview';
                                } else {
                                   $scope._event['pdf_panel'].isShown = 'N'
                                   $scope._event['pdf_footer'].isShown = 'N'   
                                   $scope.mode = 'list';
                                }
                               
                                document.getElementById('kmi-pdf-panel').src = '';
                                $scope.printList = [];
                                $scope.iframeStyle = false;
                        };

                        // 列印完成後，需把列印詳情回送給後台做記錄
                        function printWiplogProcess() {
                                $MMWService.sendToServer({
                                        uri: 'ServicesSTD.Module_SN.print_wiplog_process',
                                        content: {
                                                printList: $scope.printList
                                        },
                                        success: function () {
                                                $scope.printList = [];
                                                $scope.search();
                                        }
                                });
                        }

                        // 列印詳情開窗查詢
                        $scope.printInfoDialog = function (item) {
                                $mddProvider.UseForm('B0102_Print_Detail', () => {

                                        $mdDialog.dialog('module/moduleA/program/publicDialog/printInfoDialog.html',
                                        function (dialog) {
                                                return {
                                                        printList: {
                                                                program: 'B0102_Print_Detail',
                                                                repair_order_no: item.plot_no,  // 維修單單號
                                                                print_user: '', // 列印人員
                                                                start_date: moment().subtract(3, 'days').format('YYYY-MM-DD'), // 開始日期
                                                                start_time: moment().subtract(3, 'days').format('HH:mm:ss'), // 開始時間
                                                                end_date: moment().endOf('day').format('YYYY-MM-DD'), // 結束日期
                                                                end_time: moment().endOf('day').format('HH:mm:ss'), // 結束時間
                                                                printDetailList: [],
                                                               
                                                        },
                                                        _fn:{
                                                                'search_button':{
                                                                        click:()=>{
                                                                          dialog.search();    
                                                                        }
                                                                }
                                                             },
                                                        init: function () { // 初始化
                                                                var start_dateTime = dialog.printList.start_date + ' ' + dialog.printList.start_time, // 開始日期 + 開始時間
                                                                        end_dateTime = dialog.printList.end_date + ' ' + dialog.printList.end_time; // 結束日期 + 結束時間

                                                                $MMWService.pageNumberInfoGet({
                                                                        form_name: 'PageNo_108',
                                                                        query_condition_info: [
                                                                                { column_name: 'PRINTNO', query_mode: '2', value: '%' + dialog.printList.repair_order_no + '%', merge_condition_model: 'AND' }, // 維修單單號
                                                                                { column_name: 'CREATOR', query_mode: '2', value: '%' + dialog.printList.print_user + '%', merge_condition_model: 'AND' }, // 列印人員
                                                                                { column_name: 'CREATEDATE', query_mode: '4', value: start_dateTime, merge_condition_model: 'AND' }, // 列印时间 - 開始
                                                                                { column_name: 'CREATEDATE', query_mode: '5', value: end_dateTime, merge_condition_model: 'AND' }, // 列印时间 - 結束
                                                                                { column_name: 'PRINTTYPE', query_mode: '0', value: '1', merge_condition_model: 'AND' } // 列印類型 - 1:批次流程卡; 2:系统出站标签; 3:末站标签打印; 4:外包单打印; 5:模具维修单打印;
                                                                        ]
                                                                }, function (response) {
                                                                        if (response && response.length > 0) {
                                                                                dialog.printList.printDetailList = response;
                                                                        } else {
                                                                                dialog.printList.printDetailList = [];
                                                                                $scope.$root.showAlert($filter('translate')('common.msg.no_data'));
                                                                        }
                                                                });
                                                        },
                                                        back: function () {
                                                                dialog.hide();
                                                        },
                                                        search: function () { // 查詢
                                                                var start_dateTime = dialog.printList.start_date + ' ' + dialog.printList.start_time, // 開始日期 + 開始時間
                                                                        end_dateTime = dialog.printList.end_date + ' ' + dialog.printList.end_time; // 結束日期 + 結束時間

                                                                $MMWService.pageNumberInfoGet({
                                                                        form_name: 'PageNo_108',
                                                                        query_condition_info: [
                                                                                { column_name: 'PRINTNO', query_mode: '2', value: '%' + dialog.printList.repair_order_no + '%', merge_condition_model: 'AND' }, // 維修單單號
                                                                                { column_name: 'CREATOR', query_mode: '2', value: '%' + dialog.printList.print_user + '%', merge_condition_model: 'AND' }, // 列印人員
                                                                                { column_name: 'CREATEDATE', query_mode: '4', value: start_dateTime, merge_condition_model: 'AND' }, // 列印时间 - 開始
                                                                                { column_name: 'CREATEDATE', query_mode: '5', value: end_dateTime, merge_condition_model: 'AND' }, // 列印时间 - 結束
                                                                                { column_name: 'PRINTTYPE', query_mode: '0', value: '1', merge_condition_model: 'AND' } // 列印類型 - 1:批次流程卡; 2:系统出站标签; 3:末站标签打印; 4:外包单打印; 5:模具维修单打印;
                                                                        ]
                                                                }, function (response) {
                                                                        if (response && response.length > 0) {
                                                                                dialog.printList.printDetailList = response;
                                                                        } else {
                                                                                dialog.printList.printDetailList = [];
                                                                                $scope.$root.showAlert($filter('translate')('common.msg.no_data'));
                                                                        }
                                                                });
                                                        },
                                                        changeStartDate: function () { // 更改開始日期
                                                                $datePicker.open(dialog.printList.start_date,
                                                                        function (dialogType) {
                                                                                if (moment(dialogType.datePacker.pickDate).isBefore(dialog.printList.end_date)
                                                                                        || moment(dialogType.datePacker.pickDate).isSame(dialog.printList.end_date)) {
                                                                                        dialog.printList.start_date = moment(dialogType.datePacker.pickDate).format('YYYY-MM-DD');
                                                                                        dialogType.hide();
                                                                                }
                                                                                else
                                                                                        $scope.$root.showAlert($filter('translate')('printInfoDialog.showAlert.column01')); // 開始日期不能大於結束日期！
                                                                        },
                                                                        function (dialogType) {
                                                                                dialogType.hide();
                                                                        }, {}
                                                                );
                                                        },
                                                        changeEndDate: function () { // 更改結束日期
                                                                $datePicker.open(dialog.printList.end_date,
                                                                        function (dialogType) {
                                                                                if (moment(dialogType.datePacker.pickDate).isAfter(dialog.printList.start_date)
                                                                                        || moment(dialogType.datePacker.pickDate).isSame(dialog.printList.start_date)) {
                                                                                        dialog.printList.end_date = moment(dialogType.datePacker.pickDate).format('YYYY-MM-DD');
                                                                                        dialogType.hide();
                                                                                }
                                                                                else
                                                                                        $scope.$root.showAlert($filter('translate')('printInfoDialog.showAlert.column02')); // 結束日期不能小於開始日期！
                                                                        },
                                                                        function (dialogType) {
                                                                                dialogType.hide();
                                                                        }, {}
                                                                );
                                                        }
                                                }
                                        }
                                );
                                });
                              
                        };

                }
        ];
});
